package com.zxl.springcloud.controller;

import com.zxl.springcloud.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class StudentConsumerController {

//    private static final String URI_PRIFIX="http://127.0.0.1:7001";
    // 如果 使用了fegin,则此处前缀需要使用 服务提供者的名称
    private static final String URI_PRIFIX="http://STUDENT-PROVIDER";

    @Autowired
    private RestTemplate restTemplate;


    @PostMapping("/consumer/student/add")
    public boolean add(@RequestBody  Student student){
        return restTemplate.postForObject(URI_PRIFIX+"/student/add",student,Boolean.class);
    }

    @GetMapping("/consumer/student/get/{id}")
    public Student get(@PathVariable("id") Long id){
        System.out.println("consumer2被调用");
        return restTemplate.getForObject(URI_PRIFIX+"/student/get/"+id,Student.class);
    }


    @GetMapping("/consumer/student/findAll")
    public List<Student> findAll(){
        return restTemplate.getForObject(URI_PRIFIX+"/student/findAll",List.class);
    }
}
